﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace net.xBei.WebApi.Helper {
    /// <summary>
    /// 
    /// </summary>
    public static class AuthorizationHelper {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static string? GetSid(this ClaimsPrincipal user)
            => user.FindFirstValue(ClaimTypes.Sid);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="claimType"></param>
        /// <param name="dv"></param>
        /// <returns></returns>
        public static int GetIntValue(this ClaimsPrincipal user, string claimType, int dv) {
            var s = user.FindFirstValue(claimType);
            return !string.IsNullOrWhiteSpace(s) && int.TryParse(s, out var v) ? v : dv;
        }
    }
}
